<?php
class CreateProfiles extends CakeMigration {

/**
 * Migration description
 *
 * @var string
 * @access public
 */
	public $description = '';

/**
 * Actions to be performed
 *
 * @var array $migration
 * @access public
 */
	public $migration = array(
		'up' => array(
			'create_table' => array(
					'profiles' => array(
						'id' => array('type' => 'integer', 'null' => false, 'key'	=> 'primary'),
						'first_name' => array('type' => 'string', 'null' => false),
						'last_name' => array('type' => 'string', 'null' => false),
						'email'	=> array('type' => 'string', 'null' => false),
						'address1' => array('type' => 'string'),
						'address2' => array('type' => 'string'),
						'phone' => array('type' => 'string'),
						'created_at' => array('type' => 'datetime'),
		        'updated_at' => array('type' => 'datetime'),
						'created_by' => array('type' => 'integer'),
						'district_id' => array('type' => 'integer'),
						'city_id' => array('type' => 'integer'),
						'user_id' => array('type' => 'integer'),
						'indexes' => array(
						      'PRIMARY' => array(
						          'column' => 'id',
						          'unique' => 1)
						  )
					)
			)
		),
		'down' => array(
			'drop_table' => array('profiles')
		),
	);

/**
 * Before migration callback
 *
 * @param string $direction, up or down direction of migration process
 * @return boolean Should process continue
 * @access public
 */
	public function before($direction) {
		return true;
	}

/**
 * After migration callback
 *
 * @param string $direction, up or down direction of migration process
 * @return boolean Should process continue
 * @access public
 */
	public function after($direction) {
		App::uses('AuthComponent', 'Controller/Component');
		$User = ClassRegistry::init('User');
    if ($direction == 'up') { //add 2 records to statues table
        $data['User']['email'] = 'admin@gmail.com';
        $data['User']['name'] = 'Admin';
        $data['User']['password'] = '1qazxsw2';
        $data['User']['status'] = 1;
				$data['User']['role_id'] = 1;
				$data['User']['email_verified'] = 1;
				$data['Profile']['first_name'] = 'Admin';
				$data['Profile']['last_name'] = 'Super';
				$data['Profile']['email'] = 'admin@gmail.com';
        $User->create();
				var_dump($data);
        if($User->saveAll($data)){
            echo "Users table has been initialized";
        }
    } else if ($direction == 'down') {
        //do more work here
    }
		return true;
	}
}
